const { checkPrimeSync } = require('crypto')
const express = require('express')
const cors = require('cors')

const fs = require('fs')

const app = express()
app.use(cors())

app.engine('html', require('express-art-template'))

app.set('view engine', 'html')

app.use((req, res, next) => {
    console.log(req.url)//测试收到请求的url
    console.log(req.get('Host'))//测试请求的端口号
     res.header('Access-Control-Allow-Headers', 'Content-Type');
     res.header('Access-Control-Allow-Methods', '*');
     res.header('Content-Type', 'application/json;charset=utf-8');
    next()//一定要写next，不然中间件不会把东西给下面  
}) 

app.get('/serve', (req, res) => {
    //设置响应头， 设置允许跨域
     //res.setHeader('Access-Control-Allow-Origin', "*")
    //  res.header('Access-Control-Allow-Headers', 'Content-Type');
    //  res.header('Access-Control-Allow-Methods', '*');
    //  res.header('Content-Type', 'application/json;charset=utf-8');
    //设置响应体
    res.send('HELLO AJAX')
})




app.listen('8000', (err) => {
  
})

console.log('服务器正在运行......')
